#!groovy
@Library(["pipeline-library@master"]) _

def testingNamespace

node("maven") {
    stage("SETUP: Resolve namespace") {
        testingNamespace = sh(script: "cat /var/run/secrets/kubernetes.io/serviceaccount/namespace", returnStdout: true)
    }

    stage("TEST: Can tag image") {
        tagImage([
                sourceImagePath: "openshift",
                sourceImageName: "jenkins",
                sourceImageTag : "2",
                toImagePath    : "${testingNamespace}",
                toImageName    : "tagimage",
                toImageTag     : "2"
        ])
    }

    stage("ASSERT") {
        openshift.withCluster() {
            openshift.withProject() {
                def imageStream = openshift.selector("is", "tagimage")
                imageStream.untilEach(1) {
                    return it.object().status?.tags?.size() == 1
                }
            }
        }
    }
}
